<template>
    <div>
        <van-cell-group>
            <van-field v-model="name" placeholder="请输入商品名称" />
            <van-button type="primary" size="large" @click="addProd">添加商品</van-button>
        </van-cell-group>
    </div>
</template>

<script>
export default {
    data() {
        return {
            name: '',
        }
    },
    methods: {
        async addProd() {
            if (this.name.trim() === '') return this.$toast('商品名称不能为空');
            const {data: res} = await this.$http.post('/api/addproduct', {name: this.name});
            if (res.status !== 0) return this.$notify({ type: 'danger', message: '添加失败！' });
            this.$notify({ type: 'success', message: '添加成功！' });
            this.$router.push('/search');
        }
    }
}
</script>

<style lang="less" scoped>
.van-button {
    height: 40px;
    background: #1989fa;
    border: 1px solid #1989fa;
    line-height: 38px;
    margin: 40px 0;
}
</style>